# -*- coding: utf-8 -*-

import time
import logging
import ray

import py_global

logger = logging.getLogger(__name__)


@ray.remote
def remote_function():
    return list(range(10))


@ray.remote
def error_function():
    time.sleep(1000)
    raise Exception('message')


if __name__ == '__main__':
    ray.init()

    data: dict = {'a': 1, 'b': 2, 'c': 3}

    # ObjectStore
    object_ref = ray.put(data)

    object_refs = [ray.put(i) for i in range(10)]
    object_data = ray.get(object_refs)
    logger.warning(object_data)

    result_ref = remote_function.remote()
    result = ray.get(result_ref)
    logger.warning(result)

    try:
        error_function.remote()
    except Exception as e:
        logger.exception(e)
